import request from '@/utils/request'

/**
 * MinIO文件上传接口
 * @param {File} file - 要上传的文件对象
 * @returns {Promise} - 返回Promise对象，包含上传后的文件URL
 */
export function uploadToMinIO(file) {
    console.log('uploadToMinIO开始:', file.name, file.size);
    let formData = new FormData();
    formData.append('file', file);

    return request({
        url: '/common/minio/upload/index',
        method: 'post',
        headers: {
            "Content-Type": "multipart/form-data; charset=utf-8"
        },
        contentType: false,
        processData: false,
        withCredentials: false,
        data: formData,
        timeout: 30000 // 30秒超时
    }).then(response => {
        console.log('uploadToMinIO响应:', response);
        return response;
    }).catch(error => {
        console.error('uploadToMinIO错误:', error);
        throw error;
    });
}
